---
title: "UN Personnel Survey Analysis II"
author: "Joshua Fawcett-Weiner"
date: "19/01/2022"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## Loading Packages and Data
```{r}
## Version: Most recent analysis completed in R.4.3.1
## Setting the WD
setwd("C:/Users/joshu/OneDrive/Documents/PhD Program/TA Work/RA Work/Katia 2019/Interview Data Project - 2020")

## Loading Relevant Packages
library(MASS)
library(stargazer)
library(plm)
library(pglm)
library(lme4)
library(lmerTest)
library(ggplot2)
library(ggthemes)
library(coefplot)
library(jtools)
library(ggstance)
library(lmtest)
library(car)
library(fixest)
library(broom)
library(dplyr)
library(tidyverse)
library(psy)
library(stm)
library(tm)
library(readxl)
library(knitr)
library(haven)

## Covid Data: Load Data
covid_data_covariates1 <- readRDS("covid_data_covariates.rds")

## Trust Data: Load Data
trust_data_covariates1 <- readRDS("trust_data_covariates.rds")

# Note: the values for the mission variables in the two datasets do not necessarily align. The same value in both datasets may correspond to different missions. The values are placeholders for the mission names in order to protect respondent anonymity. 

```

## Setting up the Data for Analysis
```{r}
## Reordering the Trust Response Variables to Match Jessica's coding (-3 is worst, 3 is best)
## Management Relationship
trust_data_covariates1$SeniorLeadCommGood2 <- 7- trust_data_covariates1$SeniorLeadCommGood - 3 
trust_data_covariates1$SenManagEmplRespect2 <- 7- trust_data_covariates1$SenManagEmplRespect - 3
trust_data_covariates1$SMLSincereComm2 <- 7- trust_data_covariates1$SMLSincereComm - 3
trust_data_covariates1$SMLListensConcerns2 <- 7- trust_data_covariates1$SMLListensConcerns - 3
trust_data_covariates1$SMLKeepPromis2 <- 7- trust_data_covariates1$SMLKeepPromis - 3
trust_data_covariates1$SMLConcernStaffWellbeing2 <- 7- trust_data_covariates1$SMLConcernStaffWellbeing - 3

## Feedback
trust_data_covariates1$ConstrFeedback2 <- 7- trust_data_covariates1$ConstrFeedback - 3
trust_data_covariates1$EvalUsefulFeedback2 <- 7- trust_data_covariates1$EvalUsefulFeedback - 3

## Accountability and Performance
trust_data_covariates1$PeopleAccountable2 <- 7- trust_data_covariates1$PeopleAccountable - 3
trust_data_covariates1$HiPerfReward2 <- 7- trust_data_covariates1$HiPerfReward - 3
trust_data_covariates1$UnderPerfAddressed2 <- 7- trust_data_covariates1$UnderPerfAddressed - 3

## Supervisor Relationship
trust_data_covariates1$SupRelGood2 <- 7 - trust_data_covariates1$SupRelGood - 3
trust_data_covariates1$TellSupPrbl2 <- 7 - trust_data_covariates1$TellSupPrbl - 3
trust_data_covariates1$SupListens2 <- 7 - trust_data_covariates1$SupListens - 3
trust_data_covariates1$CanDisagreeSup2 <- 7 - trust_data_covariates1$CanDisagreeSup - 3
trust_data_covariates1$ConnectSup2 <- 7 - trust_data_covariates1$ConnectSup - 3
trust_data_covariates1$SupConcernWellbeing2 <- 7 - trust_data_covariates1$SupConcernWellbeing - 3
trust_data_covariates1$ValuesSup2 <- 7 - trust_data_covariates1$ValuesSup - 3

## Supervisor Quality
trust_data_covariates1$SupPosSpeakSubords2 <- 7 - trust_data_covariates1$SupPosSpeakSubords - 3
trust_data_covariates1$SupCommSincere2 <- 7 - trust_data_covariates1$SupCommSincere - 3
trust_data_covariates1$SupKeepPromis2 <- 7 - trust_data_covariates1$SupKeepPromis - 3
trust_data_covariates1$SupConfidential2 <- 7 - trust_data_covariates1$SupConfidential - 3
trust_data_covariates1$SupConsistent2 <- 7 - trust_data_covariates1$SupConsistent - 3
trust_data_covariates1$SupFollowThru2 <- 7 - trust_data_covariates1$SupFollowThru - 3

## Peers 
trust_data_covariates1$CoWorkerRelGood2 <- 7- trust_data_covariates1$CoWorkerRelGood - 3
trust_data_covariates1$InterEmplRespect2 <- 7- trust_data_covariates1$InterEmplRespect - 3
trust_data_covariates1$PeerConnect2 <- 7 - trust_data_covariates1$`Peer Connect` - 3
trust_data_covariates1$ValuesPeersOverlap2 <- 7- trust_data_covariates1$ValuesPeersOverlap - 3

## Creating Indices for the New Re-scaled Variables
trust_data_covariates1$mgmtindex2 <- (trust_data_covariates1$SeniorLeadCommGood2 + trust_data_covariates1$SenManagEmplRespect2 + 
                                    trust_data_covariates1$SMLSincereComm2 + trust_data_covariates1$SMLListensConcerns2 + 
                                    trust_data_covariates1$SMLKeepPromis2 + trust_data_covariates1$SMLConcernStaffWellbeing2) / 6

trust_data_covariates1$feedbackindex2 <- (trust_data_covariates1$ConstrFeedback2 + trust_data_covariates1$EvalUsefulFeedback2) / 2
  
trust_data_covariates1$accindex2 <- (trust_data_covariates1$PeopleAccountable2 + trust_data_covariates1$HiPerfReward2 + 
                                      trust_data_covariates1$UnderPerfAddressed2) / 3
  
trust_data_covariates1$suprelindex2 <- (trust_data_covariates1$SupRelGood2 + trust_data_covariates1$TellSupPrbl2 +
                                        trust_data_covariates1$SupListens2 + trust_data_covariates1$CanDisagreeSup2 +
                                        trust_data_covariates1$ConnectSup2 + trust_data_covariates1$SupConcernWellbeing2 +
                                        trust_data_covariates1$ValuesSup2) / 7
  
trust_data_covariates1$supqualindex2 <- (trust_data_covariates1$SupPosSpeakSubords2 + trust_data_covariates1$SupCommSincere2 +
                                           trust_data_covariates1$SupKeepPromis2 + trust_data_covariates1$SupConfidential2 + 
                                           trust_data_covariates1$SupConsistent2 + trust_data_covariates1$SupFollowThru2) / 6

trust_data_covariates1$peersindex2 <- (trust_data_covariates1$CoWorkerRelGood2 + trust_data_covariates1$InterEmplRespect2 +
                                         trust_data_covariates1$PeerConnect2 + trust_data_covariates1$ValuesPeersOverlap2) / 4
```

## Updated Indices
```{r}
## Peer index - peersindex2

## Combined Feedback and Performance Index
trust_data_covariates1$feedperfindex <- (trust_data_covariates1$ConstrFeedback2 + trust_data_covariates1$EvalUsefulFeedback2 +
                                         trust_data_covariates1$PeopleAccountable2 + trust_data_covariates1$HiPerfReward2 + 
                                         trust_data_covariates1$UnderPerfAddressed2) / 5

## Combined Supervisor and Mgmt Index
trust_data_covariates1$superiorsindex <- (trust_data_covariates1$SeniorLeadCommGood2 + trust_data_covariates1$SenManagEmplRespect2 +
                                    trust_data_covariates1$SMLSincereComm2 + trust_data_covariates1$SMLListensConcerns2 + 
                                    trust_data_covariates1$SMLKeepPromis2 + trust_data_covariates1$SMLConcernStaffWellbeing2 +
                                    trust_data_covariates1$SupRelGood2 + trust_data_covariates1$TellSupPrbl2 +
                                        trust_data_covariates1$SupListens2 + trust_data_covariates1$CanDisagreeSup2 +
                                        trust_data_covariates1$ConnectSup2 + trust_data_covariates1$SupConcernWellbeing2 +
                                        trust_data_covariates1$ValuesSup2 +
                                    trust_data_covariates1$SupPosSpeakSubords2 + trust_data_covariates1$SupCommSincere2 +
                                           trust_data_covariates1$SupKeepPromis2 + trust_data_covariates1$SupConfidential2 + 
                                           trust_data_covariates1$SupConsistent2 + trust_data_covariates1$SupFollowThru2) / 19

```

## Cronbach's Alpha for Indices (Part of Table B7)
```{r}
##### Cronbach's Alpha for the Indices #####

## Cronbach's Alpha for Combined Feedback and Performance Index
feedperfindex_DF <- data.frame(trust_data_covariates1$ConstrFeedback2, trust_data_covariates1$EvalUsefulFeedback2, 
                               trust_data_covariates1$PeopleAccountable2, trust_data_covariates1$HiPerfReward2,  
                                      trust_data_covariates1$UnderPerfAddressed2)
cronbach_feedperf <- cronbach(feedperfindex_DF) ## Cronbach's alpha of 0.9010925

## Cronbach's Alpha for Combined Supervisor/Mgmt Index
superiorsindex_DF <- data.frame(trust_data_covariates1$SeniorLeadCommGood2, trust_data_covariates1$SenManagEmplRespect2, 
                                    trust_data_covariates1$SMLSincereComm2, trust_data_covariates1$SMLListensConcerns2,  
                                    trust_data_covariates1$SMLKeepPromis2, trust_data_covariates1$SMLConcernStaffWellbeing2,
                                trust_data_covariates1$SupRelGood2, trust_data_covariates1$TellSupPrbl2,
                                        trust_data_covariates1$SupListens2, trust_data_covariates1$CanDisagreeSup2,
                                        trust_data_covariates1$ConnectSup2, trust_data_covariates1$SupConcernWellbeing2, 
                                        trust_data_covariates1$ValuesSup2, 
                                trust_data_covariates1$SupPosSpeakSubords2, trust_data_covariates1$SupCommSincere2,
                                           trust_data_covariates1$SupKeepPromis2, trust_data_covariates1$SupConfidential2,  
                                           trust_data_covariates1$SupConsistent2, trust_data_covariates1$SupFollowThru2)
cronbach_superiors <- cronbach(superiorsindex_DF) ## Cronbach's alpha of 0.970591

## Cronbach's Alpha for Management Index 
mgmtindex2_DF <- data.frame(trust_data_covariates1$SeniorLeadCommGood2, trust_data_covariates1$SenManagEmplRespect2, 
                                    trust_data_covariates1$SMLSincereComm2, trust_data_covariates1$SMLListensConcerns2,  
                                    trust_data_covariates1$SMLKeepPromis2, trust_data_covariates1$SMLConcernStaffWellbeing2)
cronbach_mgmt <- cronbach(mgmtindex2_DF)

## Cronbach's Alpha for Feedback Index
feedbackindex2_DF <- data.frame(trust_data_covariates1$ConstrFeedback2, trust_data_covariates1$EvalUsefulFeedback2)
cronbach_feedback <- cronbach(feedbackindex2_DF)

## Cronbach's Alpha for Performance Index
accindex2_DF <- data.frame(trust_data_covariates1$PeopleAccountable2, trust_data_covariates1$HiPerfReward2,  
                                      trust_data_covariates1$UnderPerfAddressed2)
cronbach_acc <- cronbach(accindex2_DF)

## Cronbach's Alpha for Supervisor Relationship Index
suprelindex2_DF <- data.frame(trust_data_covariates1$SupRelGood2, trust_data_covariates1$TellSupPrbl2,
                                        trust_data_covariates1$SupListens2, trust_data_covariates1$CanDisagreeSup2,
                                        trust_data_covariates1$ConnectSup2, trust_data_covariates1$SupConcernWellbeing2, 
                                        trust_data_covariates1$ValuesSup2)
cronbach_suprel <- cronbach(suprelindex2_DF)

## Cronbach's Alpha for Supervisor Quality Index
supqualindex2_DF <- data.frame(trust_data_covariates1$SupPosSpeakSubords2, trust_data_covariates1$SupCommSincere2,
                                           trust_data_covariates1$SupKeepPromis2, trust_data_covariates1$SupConfidential2,  
                                           trust_data_covariates1$SupConsistent2, trust_data_covariates1$SupFollowThru2)
cronbach_supqual <- cronbach(supqualindex2_DF)

## Cronbach's Alpha for Peer Index
peersindex2_DF <- data.frame(trust_data_covariates1$CoWorkerRelGood2, trust_data_covariates1$InterEmplRespect2, 
                                         trust_data_covariates1$PeerConnect2, trust_data_covariates1$ValuesPeersOverlap2)
cronbach_peer <- cronbach(peersindex2_DF)

```

## Descriptive Stats for Indices by Gender (Parts of Table B7)
```{r}
## Mean Peers Response by Gender
mean_peers_female <- trust_data_covariates1 %>%
      group_by(female) %>%
      summarize(mean_peers = mean(peersindex2, na.rm = TRUE))

## Mean Feedback/Performance Response by Gender
mean_feedperf_female <- trust_data_covariates1 %>%
      group_by(female) %>%
      summarize(mean_peers = mean(feedperfindex, na.rm = TRUE))

## Mean Supervisor Response by Gender
mean_superior_female <- trust_data_covariates1 %>%
      group_by(female) %>%
      summarize(mean_peers = mean(superiorsindex, na.rm = TRUE))

mean_peers_female
mean_feedperf_female
mean_superior_female

mean(trust_data_covariates1$peersindex2)
mean(trust_data_covariates1$feedperfindex)
mean(trust_data_covariates1$superiorsindex, na.rm = TRUE)
```

## Main and Supplementary Models
```{r}
## FE Peer Relationship Model
fe.peers3 <- feols(peersindex2 ~ female + age + staffcat + Contract + PKO + familyduty
                  | Mission,   
                  data = trust_data_covariates1, vcov = ~Mission)

## FE Peer Relationship Model w Family Duty Station
fe.peers3a <- feols(peersindex2 ~ female + age + staffcat + Contract + PKO + familyduty
                  ,   
                  data = trust_data_covariates1, vcov = ~Mission)

## Feedback and Performance Collapsed into One Index
fe.feedperf <- feols(feedperfindex ~ female + age + staffcat + Contract + PKO + familyduty
                  | Mission,   
                  data = trust_data_covariates1, vcov = ~Mission)

## Family Duty Station Version
fe.feedperfa <- feols(feedperfindex ~ female + age + staffcat + Contract + PKO + familyduty
                  ,   
                  data = trust_data_covariates1, vcov = ~Mission)

## Relationship w all Superiors Collapsed into One Index
fe.superiors <- feols(superiorsindex ~ female + age + staffcat + Contract + PKO + familyduty
                  | Mission,   
                  data = trust_data_covariates1, vcov = ~Mission)

## Family Duty Station Version
fe.superiorsa <- feols(superiorsindex ~ female + age + staffcat + Contract + PKO + familyduty
                  ,   
                  data = trust_data_covariates1, vcov = ~Mission)

```

## Results Tables B1 and B2 and Figure 1
```{r}
## Results Table for Comparison w UPDATED INDICES (Table B1)
etable(fe.feedperf, fe.superiors, fe.peers3,
       headers = c("Performance", "Supervisory", "Peers"))
etable(fe.feedperf, fe.superiors, fe.peers3, tex = TRUE) ## Completed using LaTeX in Overleaf

## Results Table for Comparison w UPDATED INDICES (Table B2): Family Duty Station Added
etable(fe.feedperfa, fe.superiorsa, fe.peers3a,
       headers = c("Performance", "Supervisory", "Peers"))
etable(fe.feedperfa, fe.superiorsa, fe.peers3a, tex = TRUE) ## Completed using LaTeX in Overleaf

## Plotting Only the Gendered Effects (Figure 1)
p <- plot_summs(fe.feedperf, fe.superiors, fe.peers3, 
           model.names = c("Performance", "Supervisory", "Peers"), 
           omit.coefs = "age18-24",
           coefs = c("Female"="female"
                    ), 
           scale = TRUE, robust = TRUE)

## Save the plot at a high-resolution (300 dpi)
ggsave("Figure1.png", plot = p, dpi = 300, width = 6, height = 4, units = "in")

## Predicted Probabilities of Model Results
## Prediction based on most common age (45-54), Staff category of Field Service (most common), 
## Fixed Term Contract, a PKO, no family duty station and UNMISS since it had the most respondents
newdata <- with(trust_data_covariates1, data.frame(female = c(0,1), age="45-54", 
                staffcat = "Field Service Category (FS3 - FS7)", Contract = "Fixed Term Appointment", 
                PKO = 1, familyduty = 0, Mission = "UNMISS"))

## Performance
pre.fe.feedperf <- predict(fe.feedperf, newdata, type = "response")
## Superiors Relationship (Mgmt and Supervisors)
pre.fe.superiors <- predict(fe.superiors, newdata, type = "response")
## Peers
pre.fe.peer <- predict(fe.peers3, newdata, type = "response")

```

## Interaction Effects: Table B3
```{r}
##### Interaction between Age and Gender #####
## FE Peer Relationship Model w Interaction
fe.peers3i <- feols(peersindex2 ~ i(female, age) + staffcat + Contract + PKO + familyduty
                  | Mission,   
                  data = trust_data_covariates1, vcov = ~Mission)

## Feedback and Performance in One Index w Interaction
fe.feedperfi <- feols(feedperfindex ~ i(female, age) + staffcat + Contract + PKO + familyduty
                  | Mission,   
                  data = trust_data_covariates1, vcov = ~Mission)

## Relationship w all Superiors Collapsed into One Index
fe.superiorsi <- feols(superiorsindex ~ i(female, age) + staffcat + Contract + PKO + familyduty
                  | Mission,   
                  data = trust_data_covariates1, vcov = ~Mission)

## Results Table for Interaction Models (Table B3)
etable(fe.feedperfi, fe.superiorsi, fe.peers3i,
       headers = c("Performance", "Supervisory", "Peers"))
etable(fe.feedperfi, fe.superiorsi, fe.peers3i, tex = TRUE) ## Completed using LaTeX in Overleaf

```

## Disaggregated Accountability Index: Table B9
```{r}
##### Disaggregated Accountability Index Questions #####
## Holding People Accountable 
fe.accountable <- feols(PeopleAccountable2 ~ female + age + staffcat + Contract + PKO + familyduty
                  | Mission,   
                  data = trust_data_covariates1, vcov = ~Mission)

## High Performance is Rewarded 
fe.hiperf <- feols(HiPerfReward2 ~ female + age + staffcat + Contract + PKO + familyduty
                  | Mission,   
                  data = trust_data_covariates1, vcov = ~Mission)

## Under Performance is Addressed 
fe.underperf <- feols(UnderPerfAddressed2 ~ female + age + staffcat + Contract + PKO + familyduty
                  | Mission,   
                  data = trust_data_covariates1, vcov = ~Mission)

## Output results
etable(fe.accountable, fe.hiperf, fe.underperf, tex = TRUE) ## Completed using LaTeX in Overleaf

```

## Results Using Disaggregated Indices: Table B8
```{r}
## FE Management Model
fe.mgmt3 <- feols(mgmtindex2 ~ female + age + staffcat + Contract + PKO + familyduty
                  | Mission,   
                  data = trust_data_covariates1, vcov = ~Mission)

## FE Feedback Model
fe.feedback3 <- feols(feedbackindex2 ~ female + age + staffcat + Contract + PKO + familyduty
                  | Mission,   
                  data = trust_data_covariates1, vcov = ~Mission)

## FE Accountability Model
fe.account3 <- feols(accindex2 ~ female + age + staffcat + Contract + PKO + familyduty
                  | Mission,   
                  data = trust_data_covariates1, vcov = ~Mission)

## FE Supervisor Relationship Model
fe.suprel3 <- feols(suprelindex2 ~ female + age + staffcat + Contract + PKO + familyduty
                  | Mission,   
                  data = trust_data_covariates1, vcov = ~Mission)

## FE Supervisor Quality Model
fe.supqual3 <- feols(supqualindex2 ~ female + age + staffcat + Contract + PKO + familyduty
                  | Mission,   
                  data = trust_data_covariates1, vcov = ~Mission)

etable(fe.mgmt3, fe.feedback3, fe.account3, fe.suprel3, fe.supqual3, fe.peers3, tex = TRUE)
## Completed using LaTeX in Overleaf 

```

## Covid Survey Models: Table B4 
```{r}
## Easy Work FE Models

## Subsetting the Covid surveys for Mission FE
covid_data_covariates2 <- covid_data_covariates1 %>%
                          filter(round > 1)

fe.easy <- feols(easywork ~ female + agegroup + work_alternate + permanent + fieldstaff + pko + familyduty
                  | mission,   
                  data = covid_data_covariates2, vcov = ~mission)

## Confident in Support
fe.confidsupport <- feols(confid_support ~ female + agegroup + work_alternate + permanent + fieldstaff
                          + pko + familyduty
                  | mission,   
                  data = covid_data_covariates2, vcov = ~mission)

## Experience of Counselling Support
fe.expsupport <- feols(experience_support ~ female + agegroup + work_alternate + permanent + fieldstaff
                       + pko + familyduty
                  | mission,   
                  data = covid_data_covariates2, vcov = ~mission)

## Current Mood
fe.moodcurrent <- feols(mood_current ~ female + agegroup + work_alternate + permanent + fieldstaff
                        + pko + familyduty
                  | mission,   
                  data = covid_data_covariates2, vcov = ~mission)

etable(fe.easy, fe.confidsupport, fe.expsupport, fe.moodcurrent, tex = TRUE)
## Completed using LaTeX using Overleaf

## Descriptive Info About DVs (Elements of Table B7)
summary(trust_data_covariates1$feedperfindex) ## Performance/Feedback
summary(trust_data_covariates1$superiorsindex) ## Supervisory
summary(trust_data_covariates1$mgmtindex2)
summary(trust_data_covariates1$feedbackindex2)
summary(trust_data_covariates1$accindex2)
summary(trust_data_covariates1$suprelindex2)
summary(trust_data_covariates1$supqualindex2)
summary(trust_data_covariates1$peersindex2)
summary(covid_data_covariates2$easywork)
summary(covid_data_covariates2$confid_support)
summary(covid_data_covariates2$experience_support)
summary(covid_data_covariates2$mood_current)
sum(!is.na(trust_data_covariates1$feedperfindex)) ## Performance/Feedback
sum(!is.na(trust_data_covariates1$superiorsindex)) ## Supervisory
sum(!is.na(trust_data_covariates1$mgmtindex2))
sum(!is.na(trust_data_covariates1$feedbackindex2))
sum(!is.na(trust_data_covariates1$accindex2))
sum(!is.na(trust_data_covariates1$suprelindex2))
sum(!is.na(trust_data_covariates1$supqualindex2))
sum(!is.na(trust_data_covariates1$peersindex2))

```

## Survey Sample Comparison: Table A2
```{r}
## Only includes data for the Trust and COVID I-III columns, the Staff Composition Report data is taken directly from that UN report

## Trust Column 
table(trust_data_covariates1$age) ## Trust Modal age category 45-54
#trust_data_covariates1 %>% count(Mission, sort = TRUE) ## Trust Top 5 Missions by responses 
#trust_data_covariates1 %>% filter(female == 1) %>%
#  count(Mission, sort = TRUE) ## Trust Top 5 Missions for Women by responses

# Note: anonymous missions mean that the mission-specific elements are not reproducible here. 

## Data Setup
total_n <- 1698
trust_data_covariates1$Contract <- as.factor(trust_data_covariates1$Contract)
trust_data_covariates1$female1 <- as.factor(trust_data_covariates1$female)

## Summary Table for female, staffcat, and Contract
summary_table <- trust_data_covariates1 %>%
  dplyr::select(female1, staffcat, Contract) %>%
  pivot_longer(cols = everything(), names_to = "Variable", values_to = "Value") %>%
  dplyr::group_by(Variable, Value) %>%
  dplyr::summarise(
    Count = sum(!is.na(Value)),
    .groups = "drop"
  ) %>%
  dplyr::mutate(
    Percent = round((Count / total_n) * 100, 1),
    `Percentage (%)` = paste0(Percent, "%")
  ) %>%
  dplyr::arrange(Variable)

## Table for Trust Column in Table A2
kable(summary_table, caption = "Counts and Percentages by Categorical Variables")

## Covid Data Setup
covid_n <- 3197
covid_data_covariates2$female1 <- as.factor(covid_data_covariates2$female)
covid_data_covariates2$permanent1 <- as.factor(covid_data_covariates2$permanent) ## permanent v temporary
covid_data_covariates2$fieldstaff1 <- as.factor(covid_data_covariates2$fieldstaff) ## field staff or permanent

## COVID I-III Column in Table A2
covid_data_covariates2$agegroup <- as_factor(covid_data_covariates2$agegroup)
table(covid_data_covariates2$agegroup) ## Covid Modal age category 45-54
#covid_data_covariates2 %>% count(surv_mission, sort = TRUE) ## COVID Top 5 Missions by responses
#covid_data_covariates2 %>% filter(female1 == 1) %>%
#  count(surv_mission, sort = TRUE) ## COVID Top 5 Missions for Women by responses

# Note: with mission redacted to protect respondent identity, this code will not run

## Summary Table for COVID variables
summary_table <- covid_data_covariates2 %>%
  dplyr::select(female1, permanent1, fieldstaff1) %>%
  pivot_longer(cols = everything(), names_to = "Variable", values_to = "Value") %>%
  dplyr::group_by(Variable, Value) %>%
  dplyr::summarise(
    Count = sum(!is.na(Value)),
    .groups = "drop"
  ) %>%
  dplyr::mutate(
    Percent = round((Count / covid_n) * 100, 1),
    `Percentage (%)` = paste0(Percent, "%")
  ) %>%
  dplyr::arrange(Variable)

## Table for Covid Column in Table A2
kable(summary_table, caption = "Counts and Percentages by Categorical Variables")

```

## Text Analysis: Structural Topic Model (Info for Table B10 and B11, Figures B1 and B2)
```{r}
## Note: text analysis code is omitted here, because the survey comments were redacted to protect respondent anonymity. 
```

`r knitr::knit_exit()`
```{r}
## End of Current Paper Code
```
